<?php
namespace App\Domain;

use App\Model\Assemble as ModelAssemble;

class Assemble {

    //获取某个商品正在拼团列表
    public function getAssembleList( $goods_id ) {
        $model = new ModelAssemble();
//        $data['all_num'] = $model->getAssembleListNum( $goods_id );
//        $data['data'] = $model->getAssembleList( $goods_id );
//        if( $data['data'] ){
//            foreach ( $data['data'] as $k => $v){
//                if( $v['few'] == 0 ){
//                    unset($data['data'][$k]);
//                    $data['all_num']-1;
//                }
//            }
//        }
        $data = $model->getAssembleList( $goods_id );
        if( $data ){
            foreach ( $data as $k => &$v){
                if( $v['few'] == 0 ){
                    unset($data[$k]);
                }
                //根据found_id查询当前正在拼团的user_id
                $follow_info = $model->getAssembleFollow( $v['found_id'] );
                $user_id = array();
                $user_id[] =  $v['user_id'];
                foreach ( $follow_info as $kk => $vv ){
                    $user_id[] = $vv['follow_user_id'];
                }
                $v['user_id'] = $user_id;
                $v['nickname'] = base64_decode( $v['nickname'] );
            }
        }
        return $data;
    }

    //我参与的拼团详情
    public function getAssembleDetail( $user_id, $found_id, $is_myself ) {
        $model = new ModelAssemble();
        $data = $model->getAssembleFound( $found_id );
        $follow = $model->getAssembleFollow( $found_id );
        $data['follow'] = $follow;
        if( $is_myself ){
            $goods_info = $model->getAssembleGoods( $user_id, $found_id );
        }else{
            $goods_info = $model->getAssembleGoodsFollow( $user_id, $found_id );
        }
        $data['goods_info'] = $goods_info;
//        $data = $model->getAssembleDetail( $user_id );
        return $data;
    }

}
